package com.example.myapplication11_10;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;

import com.github.mikephil.charting.charts.RadarChart;
import com.github.mikephil.charting.data.RadarData;
import com.github.mikephil.charting.data.RadarDataSet;
import com.github.mikephil.charting.data.RadarEntry;
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;

import java.util.ArrayList;
import java.util.List;

public class RadarActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_radar);
        RadarChart chart = findViewById(R.id.chart);

        List<IRadarDataSet> sets = new ArrayList<>();

        float[] f1 = {25f,52f,92f,52f,45f};//数据
        RadarDataSet d1 = getDataSet(f1,"鸡腿");


        sets.add(d1);
        d1.setColor(Color.parseColor("#00FF7F"));
        d1.setDrawFilled(true);//填充

        float[] f2 = {54f,45f,76f,45f,52f};//数据
        RadarDataSet d2 = getDataSet(f2,"鸭腿");

        sets.add(d2);
        d2.setColor(Color.parseColor("#1E90FF"));
        d2.setDrawFilled(true);//填充



        RadarData data = new RadarData(sets);
        chart.setData(data);
        chart.invalidate();//清除数据
    }
    private RadarDataSet getDataSet(float[] data,String title){
        List<RadarEntry> list = new ArrayList<>();
        for (int i= 0;i<data.length;i++){
            RadarEntry radarEntry = new RadarEntry(data[i]);
            list.add(radarEntry);
        }
        return new RadarDataSet(list,title);
    }
}
